<template>
    <div class=''>
        <p class="top_p"><el-button type="text" @click="goHome" class="sy">首页</el-button>&emsp;/&emsp;权限管理&emsp;/&emsp;权限列表</p>

           <el-table
     :data="deslist"
     style="width: 100%;height:650px"
     max-height="600">
     <el-table-column
      fixed
      type="index"
      :index="filterIndex"
      label="#"
      width="150">
     </el-table-column>
     <el-table-column
      prop="authName"
      label="权限名称"
      width="230">
     </el-table-column>
     <el-table-column
      prop="path"
      label="路径"
      width="230">
     </el-table-column>
    
     <el-table-column
      prop=""
      label="权限等级"
      width="230">
      <template slot-scope="scope">
      <el-tag v-if="scope.row.pid==0">一级权限</el-tag>
      <el-tag v-else-if="typeof(scope.row.pid) == 'number'" type="success">二级权限</el-tag>
      <el-tag v-else type="warning">三级权限</el-tag>
      </template>
      </el-table-column>
  
       </el-table>
    </div>
   
</template>

<script>
import { getdeslist,getdesAll } from "../api/getData.js";
export default {
  data() {
    return {
      deslist: []
    };
  },
  mounted() {
    this.getlist();
  },
  methods: {
    goHome() {
      this.$router.push("/greet");
    },
    getlist() {
      getdeslist().then(res => {
        // console.log(res);
        this.deslist = res.data;
      });
      getdesAll().then(res => {
        console.log(res);
        let arr =res.data
        function setlist(val){
            let newArr = []
          if(Array.isArray(val)){
          
            val.forEach(item=>{
              if(item.oldId == undefined){
              newArr.push(item)
              }
              if(item.children){
                newArr.push(...setlist(item.children))
              }
            })
          }
          return newArr
        }
        
        // console.log(setlist(arr,0));
        this.deslist = setlist(arr)
      });
    },
    filterIndex(index) {
      return index + 1;
    }
  },
  components: {}
};
</script>

<style lang='scss'>
</style>
